package com.example.dnfgamercommunitybackend.controller;

import com.example.dnfgamercommunitybackend.entity.Comment;
import com.example.dnfgamercommunitybackend.service.CommentService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
public class CommentController {

    @Resource
    private CommentService commentService;
    @PreAuthorize("hasAuthority('user:comment_comment_article')")
    @PostMapping("/comment/addComment")
    public String addComment(@RequestBody Comment comment, HttpServletRequest request){
        return commentService.addComment(comment,request.getHeader("Authorization"));
    }

    @PreAuthorize("hasAuthority('user:comment_delete_comment')")
    @GetMapping("/comment/deleteComment")
    public String deleteComment(@RequestParam int commentId,HttpServletRequest request){
        return commentService.deleteComment(commentId,request.getHeader("Authorization"));
    }
}
